package com.scau402.common.utils;

public class EuclideanDistanceCalculator {

    /**
     * 计算两个向量的欧几里得距离
     *
     * @param array1 向量1
     * @param array2 向量2
     * @return 欧几里得距离
     */
    public static double calculate(double[] array1, double[] array2) {
        if (array1.length != array2.length) {
            throw new IllegalArgumentException("The lengths of the arrays must be the same.");
        }

        double distanceSquaredSum = 0;
        for (int i = 0; i < array1.length; i++) {
            double diff = array1[i] - array2[i];
            distanceSquaredSum += diff * diff;
        }

        return Math.sqrt(distanceSquaredSum);
    }
}